package hook

import (
	"context"
	"github.com/google/uuid"
	"github.com/sirupsen/logrus"
)

type ContextHook struct {
	Context context.Context
}

func (r *ContextHook) Levels() []logrus.Level {
	return logrus.AllLevels
}

func (r *ContextHook) Fire(entry *logrus.Entry) error {

	if traceID, ok := r.Context.Value("trace_id").(uuid.UUID); ok {
		entry.Data["trace_id"] = traceID.String()
	}
	//if traceID, ok := hook.Context.Value("trace_id").(string); ok {
	//	// 将trace_id插入到日志条目中
	//	newData := make(logrus.Fields)
	//	newData["level"] = entry.Level.String()
	//	newData["trace_id"] = traceID
	//	for k, v := range entry.Data {
	//		if k != "level" {
	//			newData[k] = v
	//		}
	//	}
	//	entry.Data = newData
	//}
	return nil
}
